Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-value-parser

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-value-parser

Transforms css values and at-rule params into the tree

  • 4.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39M
decreased by-12.23%
Maintainers
3
Weekly downloads
 
Created

What is postcss-value-parser?

The postcss-value-parser package is a tool to parse and manipulate values from CSS declarations. It can be used to analyze, transform, and understand the structure of CSS property values, making it easier to work with complex CSS strings in JavaScript.

What are postcss-value-parser's main functionalities?

Parsing CSS values

This feature allows you to parse a CSS value into an abstract syntax tree (AST), which can then be traversed or manipulated. The code sample demonstrates parsing a CSS rgba color value.

const valueParser = require('postcss-value-parser');
const parsed = valueParser('rgba(34, 12, 64, 0.3)');
console.log(parsed.nodes);

Walking through parsed values

This feature allows you to walk through the nodes of the parsed value and perform operations on each node. The code sample demonstrates walking through a parsed CSS declaration to find and log pixel values.

const valueParser = require('postcss-value-parser');
const parsed = valueParser('10px solid black');
valueParser.walk(parsed.nodes, (node) => {
  if (node.type === 'word' && /px$/.test(node.value)) {
    console.log(`Found pixel value: ${node.value}`);
  }
});

Stringifying parsed values

After manipulating the parsed AST, you can convert it back to a string. The code sample demonstrates modifying a scale function's Y value and then stringifying the modified AST back into a CSS value.

const valueParser = require('postcss-value-parser');
const parsed = valueParser('scale(1, 1.2)');
parsed.nodes[1].value = 1.5;
const stringified = valueParser.stringify(parsed);
console.log(stringified);

Other packages similar to postcss-value-parser

Keywords

FAQs

Package last updated on 29 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc